num = input()
if len (num)<4:
    print(0)
    exit()
len1 = [int(num[i]) for i in range(len(num) ) ]
len2 = [int(num[i - 1] + num[i]) for i in range (1,len(num) ) ]
len3 = [int(num[i - 2]+ num[i - 1] + num[i]) for i in range (2,len(num)) ]
len4 = [int(num[i - 3] + num[i - 2]+ num[i - 1] + num[i]) for i in range (3,len(num) )   ]
mx = 0
for el in len1+len2+len3+len4:
            prost = True
            for i in range(2, el):
                if el % i == 0:
                    prost = False
            if  prost :
                mx = max(mx, el)

print(mx)
                    
